package main

import "fmt"

func intersection(nums1 []int, nums2 []int) []int {
	m1 := make(map[int]struct{})
	m2 := make(map[int]struct{})
	res := []int{}
	for _, v := range nums1 {
		m1[v] = struct{}{}
	}
	for _, v := range nums2 {
		if _, ok := m1[v]; ok {
			m2[v] = struct{}{}
		}
	}
	for k := range m2 {
		res = append(res, k)
	}
	return res
}

func main() {
	type pair struct {
		nums1, nums2 []int
		res          []int
	}
	pairs := []pair{{[]int{1, 2, 2, 1}, []int{2, 2}, []int{2}}, {[]int{4, 9, 5}, []int{9, 4, 9, 8, 4}, []int{9, 4}}}
	for _, p := range pairs {
		res := intersection(p.nums1, p.nums2)
		fmt.Println(res, p.res)
	}
}
